module teapo.docs.types.text { export function load(fullPath: string, read: (property: string) => string, write: (property: string, content: string) => void): DocumentHandler { return new TextDocumentHandler(read, write);
export class TextDocumentHandler implements DocumentHandler { private _doc: CodeMirror.Doc = null;
private _text: string = null;
private _editor: { cm: CodeMirror; host: HTMLElement; } = null; private _saveTimer = new Timer();
private _read: (property: string) => string,
private _write: (property: string, content: string) => void) { this._saveTimer.ontick = () => this.save();
if (this._text === null) { this._text = this._doc.getValue();
this._text = this._read(null);
this._doc = new CodeMirror.Doc(this.getText());
CodeMirror.on(this._doc, 'change', (instance, changeObj) => this._onDocChange(changeObj));
return this._getEditor().host;
this._saveTimer.endWaiting();
this._write(null, this.getText());
this._editor = requestEditor();